import 'package:equatable/equatable.dart';
import 'package:backend.core/core/domain/entities/api/google_play/api_google_play_purchased_subscription_cancellation_info.dart';
import 'package:backend.purchases/infrastructure/dtos/api/api_time_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/api/google_play/api_google_play_purchased_subscription_cancellation_info_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/api/google_play/api_google_play_purchased_subscription_cancellation_survey_result_dto.dart';

const kApiGooglePlayPurchasedSubscriptionUserCancellationTimeKey = 'time';
const kApiGooglePlayPurchasedSubscriptionUserCancellationSurveyResultKey = 'survey_result';

class ApiGooglePlayPurchasedSubscriptionUserCancellationInfoDto extends Equatable
    implements ApiGooglePlayPurchasedSubscriptionCancellationInfoDto {
  const ApiGooglePlayPurchasedSubscriptionUserCancellationInfoDto._internal({
    required this.timeDto,
    required this.surveyResultDto,
  });

  final ApiTimeDto timeDto;
  final ApiGooglePlayPurchasedSubscriptionCancellationSurveyResultDto surveyResultDto;

  @override
  String get type => kApiGooglePlayPurchasedSubscriptionUserCancellationInfoTypeValue;

  @override
  List<Object?> get props {
    return [
      timeDto,
      surveyResultDto,
    ];
  }

  factory ApiGooglePlayPurchasedSubscriptionUserCancellationInfoDto.fromEntity(
      ApiGooglePlayPurchasedSubscriptionUserCancellationInfo cancellationInfo) {
    final timeDto = ApiTimeDto.fromEntity(cancellationInfo.time);

    final surveyResultDto =
        ApiGooglePlayPurchasedSubscriptionCancellationSurveyResultDto.fromEntity(
            cancellationInfo.surveyResult);

    return ApiGooglePlayPurchasedSubscriptionUserCancellationInfoDto._internal(
      timeDto: timeDto,
      surveyResultDto: surveyResultDto,
    );
  }

  @override
  Map<String, dynamic> toJson() {
    return {
      kApiGooglePlayPurchasedSubscriptionCancellationInfoTypeKey: type,
      kApiGooglePlayPurchasedSubscriptionUserCancellationTimeKey: timeDto.toString(),
      kApiGooglePlayPurchasedSubscriptionUserCancellationSurveyResultKey: surveyResultDto.toJson(),
    };
  }
}
